//package org.idea.qiyu.framework.shutdown.threadpool;
//
//import java.util.concurrent.BlockingQueue;
//import java.util.concurrent.LinkedBlockingQueue;
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
///**
// * 任务队列 测试
// *
// * @Author linhao
// * @Date created in 9:47 下午 2021/7/17
// */
//public class TaskQueueTest {
//
//    public static void main(String[] args) throws InterruptedException {
//        BlockingQueue blockingQueue = new LinkedBlockingQueue();
//        for (int i = 1; i <= 10; i++) {
//            Thread.sleep(300);
//            blockingQueue.add(new Task("task-item-" + i));
//        }
//        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, blockingQueue);
//        //触发execute的同时也会触发等待队列中的任务执行
//        executor.execute(new Task("task-item-0"));
//        //shutdown则会终止让任务队列中再添加新的任务，但是已经存在于队列的任务会继续执行
//        executor.shutdown();
//        //shutdownNow 会立即终止任务的执行
////        executor.shutdownNow();
//        //已经终止的线程池不再接收新的任务
//        executor.execute(new Task("task-after-shutdown-999"));
//        System.out.println("workQueue's size=" + blockingQueue.size() + "now is shutdown");
//    }
//
//    static class Task implements Runnable {
//
//        String taskName;
//
//        public Task(String taskName) {
//            this.taskName = taskName;
//        }
//
//        @Override
//        public void run() {
//            for (int i = 0; i < 10; i++) {
//                System.out.println("task is " + taskName + " index is " + i);
//            }
//        }
//    }
//}
